package com.managerProvider.controller;

import com.alibaba.fastjson.JSON;
import com.managerProvider.service.PowerService;
import entity.ResponseMessage;
import entity.Role;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * The type Power controller.
 */
@RestController
@RequestMapping("/power")
@CrossOrigin
public class PowerController {
    /**
     * The Power service.
     */
    @Autowired
    private PowerService powerService;

    /**
     * The Logger.
     */
    private Logger logger = Logger.getLogger(this.getClass());

    /**
     * 选择所有权限
     *
     * @return {@link String}
     */
    @RequestMapping("/selectAllPower")
    public String selectAllPower() {
        ResponseMessage msg = powerService.selectAllPower();
        logger.debug("PowerController selectAllPower result:" + msg);
        return JSON.toJSONString(msg);
    }


    /**
     * 自我选择
     *
     * @return {@link String}
     */
    @RequestMapping("/selectBySelf")
    public String selectBySelf() {
        ResponseMessage msg = powerService.selectBySelf();
        logger.debug("PowerController selectBySelf result:" + msg);
        return JSON.toJSONString(msg);
    }


    /**
     * 更新PR
     *
     * @param role 角色
     * @return {@link String}
     */
    @RequestMapping("/updatePr")
    public String updatePr(@RequestBody Role role) {
        ResponseMessage msg = powerService.updatePr(role);
        logger.debug("PowerController updatePr result:" + msg);
        return JSON.toJSONString(msg);
    }


    /**
     * Query power list string.
     *
     * @return the string
     */
    @RequestMapping("/queryPowerList")
    public String queryPowerList() {
        ResponseMessage msg = powerService.queryPowerList();
        logger.debug("PowerController queryPowerList result:" + msg);
        return JSON.toJSONString(msg);
    }
}
